﻿using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Dryricenet.houTai
{
    public partial class comments_CX : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Refresh();
               Literal1.Text= "以上数据共" + AppraiseBLL.backstageNumBLL().ToString()+"条";
            }
        }
        //刷新
        public void Refresh()
        {
            GridView1.DataSource = AppraiseBLL.backstagePLCKBLL();
            GridView1.DataBind();
        }
        //查找
        protected void Search_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = AppraiseBLL.mhcxBLL(TextBox1.Text.Trim(),TextBox2.Text.Trim());
            GridView1.DataBind();
        }
        //数据表格
        protected void Export_Click(object sender, EventArgs e)
        {
            DataTable dt = AppraiseBLL.backstagePLCKBLL();
            CreateExcel(dt, "application/ms-excel", "Excel" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xls");//调用函数
        }
        /// <summary>
        /// DataTable导出到Excel
        /// </summary>
        /// <param name="dt">DataTable类型的数据源</param>
        /// <param name="FileType">文件类型</param>
        /// <param name="FileName">文件名</param>
        public void CreateExcel(DataTable dt, string FileType, string FileName)
        {
            Response.Clear();
            Response.Charset = "UTF-8";
            Response.Buffer = true;
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls\"");
            Response.ContentType = FileType;
            string colHeaders = string.Empty;
            string ls_item = string.Empty;
            DataRow[] myRow = dt.Select();
            int i = 0;
            int cl = dt.Columns.Count;
            for (int j = 0; j < dt.Columns.Count; j++)
            {
                ls_item += dt.Columns[j].ColumnName + "\t"; //栏位：自动跳到下一单元格
            }
            ls_item = ls_item.Substring(0, ls_item.Length - 1) + "\n";
            foreach (DataRow row in myRow)
            {
                for (i = 0; i < cl; i++)
                {
                    if (i == (cl - 1))
                    {
                        ls_item += row[i].ToString() + "\n";
                    }
                    else
                    {
                        ls_item += row[i].ToString() + "\t";
                    }
                }
                Response.Output.Write(ls_item);
                ls_item = string.Empty;
            }
            Response.Output.Flush();
            Response.End();
        }
        //分页
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            Refresh();
        }
    }
}